const Sequelize = require('sequelize')
module.exports = (sequelize, DataTypes) => {
  return CdDetector.init(sequelize, DataTypes)
}

class CdDetector extends Sequelize.Model {
  static init(sequelize, DataTypes) {
    super.init(
      {
        id: {
          type: DataTypes.CHAR(32),
          allowNull: false,
          primaryKey: true,
          comment: '主键',
        },
        slideId: {
          type: DataTypes.CHAR(32),
          allowNull: false,
          comment: '对应的slide',
          field: 'slide_id',
        },
        imgNum: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '分割后的图片数',
          field: 'img_num',
        },
        processed: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '当前检测的图片数量',
        },
        total: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '检测到的细胞总数',
        },
        cls1: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '类型1的细胞总数',
        },
        cls2: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '类型2的细胞总数',
        },
        cls3: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '类型3的细胞总数',
        },
        cls4: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '类型4的细胞总数',
        },
        cls5: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '类型5的细胞总数',
        },
        cls6: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '类型6的细胞总数',
        },
        createTime: {
          type: DataTypes.DATE,
          allowNull: false,
          defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
          comment: '检测开始时间',
          field: 'create_time',
        },
        updateTime: {
          type: DataTypes.DATE,
          allowNull: true,
          comment: '数据更新时间',
          field: 'update_time',
        },
        deleteTime: {
          type: DataTypes.DATE,
          allowNull: true,
          comment: '数据删除时间',
          field: 'delete_time',
        },
        status: {
          type: DataTypes.TINYINT,
          allowNull: false,
          defaultValue: 1,
          comment: '数据状态',
        },
      },
      {
        sequelize,
        tableName: 'cd_detector',
        timestamps: true,
        underscored: true,
        paranoid: true,
        createdAt: 'createTime',
        updatedAt: 'updateTime',
        deletedAt: 'deleteTime',
        indexes: [
          {
            name: 'PRIMARY',
            unique: true,
            using: 'BTREE',
            fields: [{ name: 'id' }],
          },
          {
            name: 'slide_id',
            using: 'BTREE',
            fields: [{ name: 'slide_id' }],
          },
        ],
      },
    )
    return CdDetector
  }
}
